package Hot100.Medium.LinkedList;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class LC141_DetectCycleInList {
    public static void main(String[] args) {

    }

    public boolean hasCycle(ListNode head){
        Set<ListNode> set = new HashSet<>();
        ListNode cur = head;
        while(cur != null){
            if(set.contains(cur)){
                return true;
            } else {
                set.add(cur);
            }
            cur = cur.next;
        }
        return false;
    }
}
